package com.etime.shycourse.controller.coupons;


import com.etime.shy.common.ListMessage;
import com.etime.shycourse.pojo.Coupontype;
import com.etime.shycourse.services.coupons.interfaces.CoupontypeServices;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *
 * @author wb
 * @since 2022-03-15
 */
@Api(tags = "后台-优惠券管理-优惠大券类型数据接口")
@RestController
@RequestMapping("/sys/couponType")
public class CoupontypeController {
    @Autowired
    private CoupontypeServices service;

    @ApiOperation("查询优惠劵的大类型")
    @GetMapping("/list/all")
    public ListMessage<Coupontype> selectCouponTypeAll() {
        List<Coupontype> data = service.selectCouponTypeAll ();
        ListMessage<Coupontype> msg = new ListMessage<> ();
        if (data.size () > 0) {
            msg.setCode (1);
            msg.setDatalist (data);
        } else {
            msg.setCode (0);
            msg.setMsg ("没有优惠劵的大类型");
        }
        return msg;
    }
    @ApiOperation("查询优惠劵的小类型")
    @GetMapping("/list/Small")
    public ListMessage<Coupontype> selectCouponTypeSmallTypeAll() {
        List<Coupontype> data = service.selectCouponTypeSmallTypeAll ();
        ListMessage<Coupontype> msg = new ListMessage<> ();
        if (data.size () > 0) {
            msg.setCode (1);
            msg.setDatalist (data);
        } else {
            msg.setCode (0);
            msg.setMsg ("没有优惠劵的小类型");
        }
        return msg;
    }

    @ApiOperation("根据优惠劵的大类型id，查询优惠劵的小类型")
    @GetMapping("/list/{pId}")
    public ListMessage<Coupontype> selectCouponTypeListById(@PathVariable Integer pId) {
        ListMessage<Coupontype> msg = new ListMessage<> ();
        List<Coupontype> data = service.selectCouponTypeListById (pId);
        if (data.size () > 0) {
            msg.setCode (1);
            msg.setDatalist (data);
        } else {
            msg.setCode (0);
            msg.setMsg ("没有优惠劵小类型");
        }
        return msg;
    }
}

